/*
 * MP3_Beaney - The MP3 Tag Editor is a free ID3-Tag Editor
 * Copyright (C) 2012 Bernhard Teismann, André Seipelt, Steffen Gruschka, Imanuel Rohlfing
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details. 
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */
package uInterface;

import java.awt.Desktop;
import java.awt.Image;
import java.io.File;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import model.MP3Management;

/**
 * Panel whith Control Elements for final options.
 *
 * @author Steffen Gruschka
 * @author Bernhard Teismann
 * @author André Seipelt
 * @author Imanuel Rohlfing
 * @version 1.0
 */
public class Step5 extends javax.swing.JPanel {

    /**
     * Creates new form Step5
     */
    public Step5(){
        initComponents();
        /*
         * Insert and scale the Successimage
         */
        ImageIcon original = createIcon(Messages.IMAGE_SUCCESS);
        Image img = original.getImage();
        Image newimg = img.getScaledInstance(240, 170, java.awt.Image.SCALE_SMOOTH);
        original = new ImageIcon(newimg);
        JLabel success = new JLabel();
        success.setIcon(original);
        success.setBounds(550, 140, 240, 170);
        success.setVisible(true);
        add(success);

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        errorLogButton = new javax.swing.JButton();
        showFolderButton = new javax.swing.JButton();
        textSuccess = new javax.swing.JLabel();

        setBackground(new java.awt.Color(255, 255, 255));
        setPreferredSize(new java.awt.Dimension(987, 400));

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        jLabel1.setFont(new java.awt.Font("Rockwell", 0, 16)); // NOI18N
        jLabel1.setText("Dateien erfolgreich editiert!");

        jLabel2.setFont(new java.awt.Font("Rockwell", 0, 16)); // NOI18N
        jLabel2.setText("Was möchten Sie jetzt machen?");

        jButton1.setFont(new java.awt.Font("Lucida Grande", 0, 16)); // NOI18N
        jButton1.setText("Weitere Dateien editieren");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        errorLogButton.setFont(new java.awt.Font("Lucida Grande", 0, 16)); // NOI18N
        errorLogButton.setText("Fehlerlog Anzeigen");
        errorLogButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                errorLogButtonActionPerformed(evt);
            }
        });

        showFolderButton.setFont(new java.awt.Font("Lucida Grande", 0, 16)); // NOI18N
        showFolderButton.setText("Zeige Ordner");
        showFolderButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showFolderButtonActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                    .add(showFolderButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel2)
                    .add(jButton1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel1)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, errorLogButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .add(77, 77, 77))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(33, 33, 33)
                .add(jLabel1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel2)
                .add(38, 38, 38)
                .add(jButton1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(errorLogButton)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(showFolderButton)
                .addContainerGap(27, Short.MAX_VALUE))
        );

        textSuccess.setFont(new java.awt.Font("Rockwell", 0, 48)); // NOI18N
        textSuccess.setText("Erfolg!");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap(452, Short.MAX_VALUE)
                .add(textSuccess)
                .add(385, 385, 385))
            .add(layout.createSequentialGroup()
                .add(270, 270, 270)
                .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 276, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(441, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .add(36, 36, 36)
                .add(textSuccess)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(58, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Setter for manager.
     * <p/>
     * @param manage MP3Manager
     */
    public void setMP3Manager(MP3Management manage){
        /*
         * necessary to use the MP3Manager in this step
         */
        manager = manage;
    }

    /**
     * Setter for MainInterface.
     * <p/>
     * @param mi MainInterface
     */
    public void setMainInterface(MainInterface mi){
        /*
         * setting the maininterface
         */
        mainInterface = mi;
    }

    /*
     * Restart the Program
     */
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        mainInterface.goToStart();
    }//GEN-LAST:event_jButton1ActionPerformed

    /*
     * Opens the Errorlog-Data, which is created in MP3Management.java
     */
    private void errorLogButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_errorLogButtonActionPerformed

        try{


            String tmp = System.getProperty("user.dir") + File.separator + "Error.txt";


            System.out.println(tmp);
            manager.writeExceptions(tmp);
            if (Desktop.isDesktopSupported()){

                Desktop.getDesktop().open(new File(tmp));
            }
        }catch (Exception io){
            System.out.println("fail!");

        }

    }//GEN-LAST:event_errorLogButtonActionPerformed

    /*
     * Opens Folder with the recently modified files
     */
    private void showFolderButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showFolderButtonActionPerformed
        if (Desktop.isDesktopSupported()){
            try{

                Desktop.getDesktop().open(manager.getPath());

            }catch (Exception e){
            }
        }
    }//GEN-LAST:event_showFolderButtonActionPerformed

    private ImageIcon createIcon(String path){
        java.net.URL imgUrl = getClass().getResource(path);
        if (imgUrl != null){
            return new ImageIcon(imgUrl);
        }else{
            return null;
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton errorLogButton;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JButton showFolderButton;
    private javax.swing.JLabel textSuccess;
    // End of variables declaration//GEN-END:variables
    private MainInterface mainInterface;
    private MP3Management manager;
}
